/**
 * @author LKQ
 * @date 2021/12/23 19:58
 * @description 迭代
 */
public class FormalSolution {
    public static void main(String[] args) {

    }

    public ListNode reverseList(ListNode head) {
        // 设置前置节点
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            ListNode next = curr.next;
            // 当前头节点指向空，
            curr.next = prev;
            // prev指向当前头节点
            prev = curr;
            // 头节点指向下一个节点
            curr = next;
        }
        return prev;
    }

}
